package com.ruoyi.common.utils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * 订单号工具类
 * @author user
 */
public class OrderNumberUtils {


    public static String createOrderNumber() {
        //获取当前年月日时分秒毫秒
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSSS");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));//设置北京时间
        String dateTime = simpleDateFormat.format(new Date());
        int radom = (int) ((Math.random() * 9 + 1) * 100000);//6位随机数
        return dateTime+radom;
    }


    /**
     * 元转分
     * @param amount
     * @return
     */

    /**
     * 将单位为元的金额转换为单位为分
     *
     * @param yuan 单位为元的字符型值
     * @return
     */
    public static int yuanZhuanFen(BigDecimal yuan) {
        int value = 0;
        try {
            BigDecimal fen = yuan.multiply(new BigDecimal(100));
            value = Integer.parseInt(fen.stripTrailingZeros().toPlainString());
        } catch (Exception e) {
            throw new IllegalArgumentException(String.format("非法金额[%s]", yuan));
        }
        return value;
    }


    public static void main(String[] args) {
        String orderNumber = createOrderNumber();
        System.out.println("orderNumber = " + orderNumber);
    }


}
